package main

import (
	"chuanyouFive/models"
	_ "chuanyouFive/routers"
	"fmt"

	"github.com/beego/beego/v2/client/orm"
	beego "github.com/beego/beego/v2/server/web"
	_ "github.com/go-sql-driver/mysql"
)

func init() {
	fmt.Println("版权归罗老师. 学号：2345678")
}

func main() {
	// 连接mysql数据库
	sqlConn, err := beego.AppConfig.String("mysqlConn")
	if err != nil {
		fmt.Println("参数获取失败:", err.Error())
		return
	}
	orm.RegisterDataBase("default", "mysql", sqlConn)
	// 连接redis数据库
	models.ConnectRedis()
	result := models.ImportAllStudentsToRedis()
	if result == false {
		fmt.Println("导入学生数据失败")
		return
	}
	if beego.BConfig.RunMode == "dev" {
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
	}

	// 将views目录  挂载的网站的 / 目录下
	beego.SetStaticPath("/", "views")
	beego.SetStaticPath("/static", "static")
	beego.Run()
}
